import { defineStore } from "pinia";

export default defineStore("user", {
  state: () => {
    return {
      accessMenus: [], // 动态树形路由菜单
      authUser: {}, // 用户信息
      permissionList: [], // 用户权限列表
      hasInitAsyncRoutes: false, // 是否初始化同步路由
      isListenDataLoopFlag: false, // 是否打开数据监听 用于是否建立数据连接
    };
  },
  getters: {},
  actions: {
    setAccessMenus(val) {
      this.accessMenus = val;
    },
    setUserInfo(val) {
      this.authUser = val;
      this.permissionList = val.permissionCodes;
    },
    setInitRoutes(val) {
      this.hasInitAsyncRoutes = val;
    },
    setListenFlag(data) {
      this.isListenDataLoopFlag = data;
    },
  },
  persist: {
    storage: sessionStorage,
  },
});
